 package com.oocl.customer.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.oocl.customersystem.service.CustomerManager;
import com.oocl.customersystem.service.impl.CustomerManagerImpl;

/**
 * Servlet implementation class RegisterServlet
 */
public class RegisterServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private CustomerManager cManager;
	
	public RegisterServlet(){
		super();
		cManager=new CustomerManagerImpl();
	}

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String cname=request.getParameter("cname");
		String pwd=request.getParameter("pwd");
		
		if (cManager.addCustomer(cname, pwd)==1) {
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}else{
			request.setAttribute("regError", "注册出错，重新注册！！！");
			request.getRequestDispatcher("register.jsp").forward(request, response);
		}		
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
